#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:6031)

#include <string>
using namespace std;

string multiply(string num1, string num2)
{
    string result;
    string tmp;
    int digit = 0;
    int carryOn = 0;
    int k = 0;

    for (int j = num2.size() - 1; j >= 0; --j)
    {
        carryOn = 0;
        for (int i = num1.size() - 1; i >= 0; --i)
        {
            digit = (num1[i] - '0') * (num2[j] - '0') + carryOn;
            carryOn = digit / 10;
            digit = digit % 10;
            tmp += digit + '0';
        }
        if (carryOn != 0)
        {
            tmp += carryOn + '0';
        }

        k = num2.size() - 1 - j;
        carryOn = 0;
        for (int i = 0; i < tmp.size(); ++i)
        {
            if (k < result.size())
            {
                digit = (tmp[i] - '0') + (result[k] - '0') + carryOn;
            }
            else
            {
                digit = (tmp[i] - '0') + carryOn;
            }
            carryOn = digit / 10;
            digit = digit % 10;
            if (k < result.size())
            {
                result[k] = digit + '0';
            }
            else
            {
                result += digit + '0';
            }
            ++k;
        }
        if (carryOn == 1)
        {
            result += '1';
        }

        tmp.clear();
    }
    reverse(result.begin(), result.end());
    return result;
}

int main()
{
    string s1("9");
    string s2("9");
    multiply(s1, s2);

    return 0;
}